#include "mainwindow.h"
#include "ui_mainwindow.h"

#include <QToolBar>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 获取图片
    QPixmap pix1(":/2.png");
    QPixmap pix2(":/3.png");
    QIcon icon1(pix1);
    QIcon icon2(pix2);
    // 创建菜单栏
    QMenuBar *menubar = this->menuBar();
    this->setMenuBar(menubar);
    // 创建菜单
    QMenu *menu = new QMenu("文件");
    menubar->addMenu(menu);


    // 创建工具栏
    QToolBar *toolbar = new QToolBar(this);
    this->addToolBar(toolbar);

    // 创建菜单项
    QAction *action1 = new QAction("运行");
    QAction *action2 = new QAction("查询");

    // 添加图片
    action1->setIcon(icon1);
    action2->setIcon(icon2);

    // 把菜单项放入菜单栏中
    menu->addAction(action1);
    menu->addAction(action2);
    // 把菜单项目放到工具栏中
    toolbar->addAction(action1);
    toolbar->addAction(action2);

    connect(action1,&QAction::triggered,this,&MainWindow::handle1);
    connect(action2,&QAction::triggered,this,&MainWindow::handle2);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::handle1()
{
    qDebug() << "运行";
}

void MainWindow::handle2()
{
    qDebug() << "查询";
}
